package com.yl.web.controller.api;

import com.yl.common.annotation.Anonymous;
import com.yl.common.core.domain.AjaxResult;
import com.yl.domain.ConferenceApplyDO;
import com.yl.domain.ConferenceCourseDO;
import com.yl.domain.ConferenceDO;
import com.yl.websocket.WebSocketUsers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.Session;
import java.util.Map;

@RequestMapping("/webs")
@RestController
@Anonymous
public class WebsocketController {
    private static final Logger log = LoggerFactory.getLogger(WebsocketController.class);


    @RequestMapping("/getUserList")
    @ResponseBody
    public AjaxResult getCourseById(@RequestBody ConferenceCourseDO conferenceCourseDO) {
        log.info("根据频道id查询频道内所有在线人数 ======【入参】==conferenceId - {}", conferenceCourseDO.getConferenceId());
        Map<Long, Session> users = WebSocketUsers.getUsers(conferenceCourseDO.getConferenceId());
        return AjaxResult.success(users);
    }

    /**
     * 清空频道人员
     *
     * @author : y
     * @date :  2024/7/17 9:30
     **/
    @RequestMapping("/deleteUserList")
    @ResponseBody
    public AjaxResult deleteUserList(@RequestBody ConferenceCourseDO conferenceCourseDO) {
        log.info("清空频道内全部人员接口======【入参】==conferenceId - {}", conferenceCourseDO.getConferenceId());
        return AjaxResult.success(WebSocketUsers.deleteUserList(conferenceCourseDO.getConferenceId()));
    }

    /**
     * 清空频道内固定的人员
     * @author : y
     * @date :  2024/7/17 9:30
     **/
    @RequestMapping("/deleteUserByStudentId")
    @ResponseBody
    public AjaxResult deleteUserList(@RequestBody ConferenceApplyDO conferenceCourseDO) {
        log.info("删除频道内固定的人员======【入参】==conferenceId - {}\n studentId - {}",
                conferenceCourseDO.getConferenceId(), conferenceCourseDO.getId());
        return AjaxResult.success(WebSocketUsers.deleteUserByStudentId(conferenceCourseDO.getConferenceId(), conferenceCourseDO.getId()));
    }
}
